package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.DTO.RoleAndWorkersAndBeautyCareDTO;
import com.example.demo.entity.DTO.RoleDTO;
import com.example.demo.entity.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 角色表 Mapper 接口
 * </p>
 *
 * @author Mr.wyy
 * @since 2024-06-03
 */
@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    //根据bc_id查询工作内容
    @Select("SELECT\n" +
            "t1.*,t3.role_name,t5.work_name\n" +
            "FROM\n" +
            "workers t1\n" +
            "INNER JOIN workers_and_role t2\n" +
            "ON t1.workers_id = t2.workers_id\n" +
            "INNER JOIN role t3\n" +
            "ON t3.role_key = t2.role_key\n" +
            "INNER JOIN workers_and_bc t4\n" +
            "ON t1.workers_id = t4.workers_id\n" +
            "INNER JOIN beauty_care t5\n" +
            "ON t4.bc_id = t5.bc_id\n" +
            "WHERE t1.workers_id = #{workersId}")
    RoleAndWorkersAndBeautyCareDTO selectRoleAndWorkersAndBeautyCare(@Param("workersId") Integer workersId);

    @Select("SELECT t1.* FROM role t1\n" +
            "INNER JOIN workers_and_role t2\n" +
            "ON t2.role_key = t1.role_key\n" +
            "WHERE t2.workers_id = #{workersId}")
    Role selectRoleByWorkersId(@Param("workersId") Integer workersId);

    //查询所有角色信息
    @Select("SELECT * FROM role WHERE flag = 1")
    List<Role> selectAllsRole();

    //根据RoleId查询角色信息
    @Select("SELECT * FROM role WHERE role_id = #{roleId}")
    Role selectRoleById(@Param("roleId") Integer roleId);

    //新增角色
    @Insert("INSERT INTO role(role_name,role_key,create_time) VALUES(#{roleName},#{roleKey},NOW())")
    int addRole(RoleDTO roleDTO);

    //根据id删除角色
    @Delete("DELETE FROM role WHERE role_id = #{roleId}")
    int deleteRole(@Param("roleId") Integer roleId);

    //根据id修改角色信息
    @Update("UPDATE role SET role_name = #{roleName} WHERE role_id = #{roleId}")
    int updateRole(RoleDTO roleDTO);




}
